package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/changdu/config"
	"net/http"
	"net/url"
)

type UserRechargeV1ApiService service

type UserRechargeV1GetRequest struct {
	ctx              context.Context
	ApiService       *UserRechargeV1ApiService
	distributorId    *uint64
	begin            *uint64
	end              *uint64
	offset           *uint32
	limit            *uint32
	deviceId         *string
	outsideTradeNo   *string
	paid             *bool
	optimizerAccount *string
	openId           *string
	externalId       *string
	orderType        *uint
}

type UserRechargeV1GetResponse struct {
	Code       *int64                     `json:"code,omitempty"`
	Message    *string                    `json:"message,omitempty"`
	HasMore    *bool                      `json:"has_more,omitempty"`
	NextOffset *int64                     `json:"next_offset,omitempty"`
	Result     []*UserRechargeV1GetResult `json:"result,omitempty"`
}

type UserRechargeV1GetResult struct {
	DeviceId         *string `json:"device_id,omitempty"`
	OpenId           *string `json:"open_id,omitempty"`
	OutTradeNo       *string `json:"out_trade_no,omitempty"`
	PayWay           *uint   `json:"pay_way,omitempty"`
	PayFee           *uint64 `json:"pay_fee,omitempty"`
	Status           *int    `json:"status,omitempty"`
	CreateTime       *string `json:"create_time,omitempty"`
	PayTime          *string `json:"pay_time,omitempty"`
	PromotionId      *uint64 `json:"promotion_id,omitempty"`
	BookId           *uint64 `json:"book_id,omitempty"`
	IsActivity       *bool   `json:"is_activity,omitempty"`
	TradeNo          *uint64 `json:"trade_no,omitempty"`
	RegisterTime     *string `json:"register_time,omitempty"`
	RecentReadBookId *string `json:"recent_read_book_id,omitempty"`
	ExternalId       *string `json:"external_id,omitempty"`
	OrderType        *uint   `json:"order_type,omitempty"`
}

func (r *UserRechargeV1GetRequest) DistributorId(distributorId uint64) *UserRechargeV1GetRequest {
	r.distributorId = &distributorId
	return r
}

func (r *UserRechargeV1GetRequest) Begin(begin uint64) *UserRechargeV1GetRequest {
	r.begin = &begin
	return r
}

func (r *UserRechargeV1GetRequest) End(end uint64) *UserRechargeV1GetRequest {
	r.end = &end
	return r
}

func (r *UserRechargeV1GetRequest) Offset(offset uint32) *UserRechargeV1GetRequest {
	r.offset = &offset
	return r
}

func (r *UserRechargeV1GetRequest) Limit(limit uint32) *UserRechargeV1GetRequest {
	r.limit = &limit
	return r
}

func (r *UserRechargeV1GetRequest) OptimizerAccount(optimizerAccount string) *UserRechargeV1GetRequest {
	r.optimizerAccount = &optimizerAccount
	return r
}

func (r *UserRechargeV1GetRequest) DeviceId(deviceId string) *UserRechargeV1GetRequest {
	r.deviceId = &deviceId
	return r
}

func (r *UserRechargeV1GetRequest) OutsideTradeNo(outsideTradeNo string) *UserRechargeV1GetRequest {
	r.outsideTradeNo = &outsideTradeNo
	return r
}

func (r *UserRechargeV1GetRequest) Paid(paid bool) *UserRechargeV1GetRequest {
	r.paid = &paid
	return r
}

func (r *UserRechargeV1GetRequest) OpenId(openId string) *UserRechargeV1GetRequest {
	r.openId = &openId
	return r
}

func (r *UserRechargeV1GetRequest) ExternalId(externalId string) *UserRechargeV1GetRequest {
	r.externalId = &externalId
	return r
}

func (r *UserRechargeV1GetRequest) OrderType(orderType uint) *UserRechargeV1GetRequest {
	r.orderType = &orderType
	return r
}

func (r *UserRechargeV1GetRequest) Execute() (*UserRechargeV1GetResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *UserRechargeV1GetRequest) SecretKey(SecretKey string) *UserRechargeV1GetRequest {
	r.ctx = context.WithValue(r.ctx, config.SecretKey, SecretKey)
	return r
}

func (r *UserRechargeV1GetRequest) WithLog(enable bool) *UserRechargeV1GetRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *UserRechargeV1ApiService) Get(ctx context.Context) *UserRechargeV1GetRequest {
	return &UserRechargeV1GetRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *UserRechargeV1ApiService) getExecute(r *UserRechargeV1GetRequest) (*UserRechargeV1GetResponse, *http.Response, error) {
	var (
		localVarPath         = a.client.Cfg.GetBasePath() + "/novelsale/openapi/user/recharge/v1"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *UserRechargeV1GetResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasReqParam(r.distributorId, "DistributorId"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	localVarQueryParams.Add("distributor_id", toString(r.distributorId))

	if r.begin != nil {
		localVarQueryParams.Add("begin", toString(r.begin))
	}
	if r.end != nil {
		localVarQueryParams.Add("end", toString(r.end))
	}
	if r.offset != nil {
		localVarQueryParams.Add("offset", toString(r.offset))
	}
	if r.limit != nil {
		localVarQueryParams.Add("limit", toString(r.limit))
	}
	if r.optimizerAccount != nil {
		localVarQueryParams.Add("optimizer_account", toString(r.optimizerAccount))
	}
	if r.deviceId != nil {
		localVarQueryParams.Add("device_id", toString(r.deviceId))
	}
	if r.outsideTradeNo != nil {
		localVarQueryParams.Add("outside_trade_no", toString(r.outsideTradeNo))
	}
	if r.paid != nil {
		localVarQueryParams.Add("paid", toString(r.paid))
	}
	if r.openId != nil {
		localVarQueryParams.Add("open_id", toString(r.openId))
	}
	if r.externalId != nil {
		localVarQueryParams.Add("external_id", toString(r.externalId))
	}
	if r.orderType != nil {
		localVarQueryParams.Add("order_type", toString(r.orderType))
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
